package com.example.calculator;

public class MathUtils {

    // 修复后的阶乘实现
    public static int factorial(int n) {
        if (n < 0) {
            throw new IllegalArgumentException("输入必须为非负整数");
        }

        int result = 1;  // 修复：正确初始化为1
        for (int i = 1; i <= n; i++) {
            result *= i;
        }
        return result;
    }

    public static boolean isPrime(int number) {
        if (number <= 1) return false;
        for (int i = 2; i <= Math.sqrt(number); i++) {
            if (number % i == 0) return false;
        }
        return true;
    }
}